<template>
  <div>
    <BasicTable @register="registerTable">
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" />
      </template>
    </BasicTable>
    <CompanyUserGoodsSendMessageDrawer @register="registerCompanyUserGoodsSendMessageDrawer" />
  </div>
</template>
<script lang="ts" setup>
import { ActionItem, BasicTable, TableAction } from '@apps/antd-admin/src/components/table';
import { useBaseTable } from '@apps/antd-admin/src/hooks';
import { columns, searchFormSchema } from '../data/UserGoodsData';
import { UserGoodsApi } from '../data/UserGoodsApi';
import { useDrawer } from '@apps/antd-admin/src/components/drawer';
import CompanyUserGoodsSendMessageDrawer from './CompanyUserGoodsSendMessageDrawer.vue';

const [registerCompanyUserGoodsSendMessageDrawer, { openDrawer: openCompanyUserGoodsSendMessageDrawer }] = useDrawer();
const { prefixCls, tableContext, handleDelete, handleSuccess, handlePost, handleBatchDelete } = useBaseTable({
  designScope: 'companyUserGoodsIndex-template',
  tableProps: {
    //表格标题
    title: '券码列表',
    //主键字段
    rowKey: 'userGoodsId',
    //列表查询handler
    handlerName: 'companyUserGoodsListHandler',
    //列表接口
    listUrl: UserGoodsApi.page,
    //列定义
    columns,
    //查询表单配置
    formConfig: {
      labelWidth: 150,
      labelCol: { span: 5 },
      schemas: searchFormSchema,
    },
    //操作列配置
    actionColumn: {
      width: 80,
      title: '操作',
      dataIndex: 'action',
      slots: { customRender: 'action' },
      fixed: 'right',
    },
  },
});

const [registerTable, { reload, setProps }, { rowSelection, hasSelectedRows }] = tableContext;

/**
 * 行内操作栏
 */
function getTableAction(record): ActionItem[] {
  return [
    {
      label: '发送信息',
      onClick: handleSendMsg.bind(null, record),
      disabled: record.refundState == 3 || record.isVipCard == 1,
    },
  ];
}

function handleSendMsg(record: Recordable) {
  openCompanyUserGoodsSendMessageDrawer(true, {
    record,
    isUpdate: true,
  });
}

function setSearchInfoProps(businessId) {
  console.info('businessId', businessId);
  setProps({ searchInfo: { businessId: businessId } });
}

defineExpose({
  setSearchInfoProps,
});
</script>
